//
//  ManagerTableViewController.m
//  Kids
//
//  Created by tengfei on 14/11/22.
//  Copyright (c) 2014年 90's Technology Co.Ltd. All rights reserved.
//

#import "ManagerTableViewController.h"
#import "ActionSheet.h"
#import "AboutViewController.h"
#import "AboutView.h"
#import "TermsOfUseViewController.h"
#import "ExitView.h"
#import "LoginViewController.h"

#import "DeviceManagerViewController.h"
@interface ManagerTableViewController () <AboutDelegate,ExitDelegate>

@end

@implementation ManagerTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.backgroundColor = [UIColor colorWithRed:0xf5 / 255.0 green:0xf0 / 255.0 blue:0xeb / 255.0 alpha:1.0];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{

    return 3;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"account" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }

    if (indexPath.section == 0 && indexPath.row == 1) {
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"device" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;


        return cell;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"about" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    if (indexPath.section == 2) {

        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"logout" forIndexPath:indexPath];
        cell.textLabel.textColor = [UIColor colorWithRed:0xff / 255.0 green:0xd7 / 255.0 blue:0x74 / 255.0 alpha:1.0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    return nil;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    if(indexPath.section == 0 && indexPath.row ==1){
        DeviceManagerViewController * controller = [[DeviceManagerViewController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        AboutView* aboutView = [[AboutView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        aboutView.delegate = self;
        [aboutView showFromBottomInView:self.view];
    }
    if(indexPath.section==2&&indexPath.row==0){
        ExitView * exitView = [[ExitView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
        exitView.delegate=self;
        [exitView showFromBottomInView:self.view];
    }
}

- (void)aboutView:(AboutView*)aboutView didSelectedButtonAtIndex:(NSInteger)index
{
    if (index == 0) {

        TermsOfUseViewController* viewController = [[TermsOfUseViewController alloc] init];
        viewController.title = @"使用条款";
        [self.navigationController pushViewController:viewController animated:YES];
    }
    if (index == 1) {
        TermsOfUseViewController* viewController = [[TermsOfUseViewController alloc] init];
        viewController.title = @"隐私政策";
        [self.navigationController pushViewController:viewController animated:YES];
    }
}

-(void)exitView:(ExitView *)aboutView didSelectedButtonAtIndex:(NSInteger)index{
    if (index == 0) {
        LoginViewController * loginViewController = [[LoginViewController alloc]init];
        
        [self presentViewController:loginViewController animated:YES completion:^{
             [self.navigationController popToRootViewControllerAnimated:NO];
        }];
        
    }
}
@end
